Zepto(function ($) {
  window.onload=function () {
    initview();
  }
  var state="";// 订单状态
  /**
   * 初始化tab 页选中状态
   *
   */
  function initview() {
    var code = sessionStorage.getItem("code");
    if(code == "code02"){
      $(".tab>div").removeClass("active");
      $(".tab2").addClass('active');
      state = "0";
      getorderlist(state);
    }
    if(code == "code03"){
      $(".tab>div").removeClass("active");
      $(".tab3").addClass('active');
      state = "1";
      getorderlist(state);
    }
    if(code == "code04"){
      $(".tab>div").removeClass("active");
      $(".tab4").addClass('active');
      state = "2";
      getorderlist(state);
    }
    if(code == "code01"){
      $(".tab>div").removeClass("active");
      $(".tab1").addClass('active');
      state = "";
      getorderlist(state);

    }
  }

  /**
   * 返回上一页
   *
   */
  $(".nav-header").on("click", ".back", function (e) {
    window.location.href = "/usercenter/member.html"
  });

  /**
   * 点击选中tab
   *
   */
  $(".tab").on("click", "div", function () {
    $(".tab>div").removeClass("active");
    $(this).addClass('active');
    $("#list").html("");
    next = 0;
    $('#spinner').show();
    $('#spinner')[0].innerHTML="点击加载更多";
    // $('#popuerSpin').css("display","block");
  });

  /**
   * 全部
   *
   */
  $(".tab").on("click", ".tab1", function () {
    state = "";
    getorderlist(state);
  });
  /**
   * 待付款
   *
   */
  $(".tab").on("click", ".tab2", function () {
    state = "0";
    getorderlist(state);
  });
  /**
   * 待发货
   *
   */
  $(".tab").on("click", ".tab3", function () {
    state = "1";
    getorderlist(state);
  });
  /**
   * 待收货
   *
   */
  $(".tab").on("click", ".tab4", function () {
    state = "2";
    getorderlist(state);
  });
  /**
   * 跳转订单详情
   *
   */
  $("body").on("click", ".list", todetails);
   function todetails(event) {
    event.stopPropagation();//阻止冒泡时间
    var code = $(this)[0].getAttribute("data-type");
    var zOrderInfoId = $(this)[0].getAttribute("data-orderId");
    sessionStorage.setItem("zOrderInfoId",zOrderInfoId);
    if(code == "code01"){
      window.location.href = "/usercenter/order/waitPaymentDetails.html";
    }
    if(code == "code02"){
      window.location.href = "/usercenter/order/waitDeliverDetails.html";
    }
    if(code == "code03"){
      window.location.href = "/usercenter/order/waitAcceptDeliverDetails.html";
    }
    if(code == "code04"){
      //已收货
      window.location.href = "/usercenter/order/resolvedDetails.html";
    }
    if(code == "code05"){
      //已取消
      window.location.href = "/usercenter/order/cancleDetails.html";
    }
    if(code == "code06"){
      //售后中
      window.location.href = "/usercenter/order/aftersale.html";
    }
  }

  /**
   * 上拉加载具体业务实现
   * =====================================================================================================================
   */
  var next = 0;
  // function lowEnough(){
  //   var pageHeight = Math.max(document.body.scrollHeight,document.body.offsetHeight);
  //   var viewportHeight = window.innerHeight ||
  //       document.documentElement.clientHeight ||
  //       document.body.clientHeight || 0;
  //   var scrollHeight = window.pageYOffset ||
  //       document.documentElement.scrollTop ||
  //       document.body.scrollTop || 0;
  //   return pageHeight - viewportHeight - scrollHeight < 20;
  // }
  // var doSomething = function(){
  //   getorderlist(state);
  //   pollScroll();//继续循环
  //   $('#spinner').hide();
  // }
  // var checkScroll = function() {
  //   if(!lowEnough()) return pollScroll();
  //   $('#spinner').show();
  //   setTimeout(doSomething,1000);
  // }
  // var pollScroll = function(){
  //   setTimeout(checkScroll,1000);
  // }
  /**
   * =====================================================================================================================
   */
  $("#spinner").click(function () {
    getorderlist(state);
  });

  /**
   * 获取订单列表
   *
   * @param state
   */
  function getorderlist(state) {
    $.ajax({
      type: 'GET',
      url: getUrl + '/wxmall/order/selectOrderList',
      data: {
        "state": state,
        "current":next,
        "limit": 5
      },
      dataType: 'json',
      timeout: 15000,
      headers: headers("order.selectOrderList"),
      success: function(data){
        viewInitList(data)
      },
      error: function(xhr, type){
      }
    });
  }

  /**
   * 初始化订单列表
   *
   * @param data
   */
  function viewInitList(data) {
    console.log(data);
    if(!data.success) {
      return
    }
    var data2 = data.data;
    var data1 = data2.list;
    next = data2.next;
    if(data2.listSize == 0){
      $('#spinner')[0].innerHTML="亲~ 没有更多了";
      setTimeout(function () {
        $('#spinner').hide();
      },2000);
    }
    if(data1 == null){
      return
    }
    var table = document.body.querySelector('#list');
    for (var i = 0; i < data1.length; i++) {
      var zorder_no = "";
      if(data1[i].zorder_no != null && data1[i].zorder_no != undefined){
        zorder_no = data1[i].zorder_no;
      }
      var zorderinfo_id = "";
      if(data1[i].zorderinfo_id != null && data1[i].zorderinfo_id != undefined){
        zorderinfo_id = data1[i].zorderinfo_id;
      }
      var zstate = "";
      if(data1[i].zstate != null && data1[i].zstate != undefined){
        zstate = data1[i].zstate;
      }
      var zstateType = "";
      if(data1[i].zstateType != null && data1[i].zstateType != undefined){
        zstateType = data1[i].zstateType;
      }
      var zorder_total_money = "";
      if(data1[i].zorder_total_money != null && data1[i].zorder_total_money != undefined){
        zorder_total_money ="￥" + data1[i].zorder_total_money;
      }
      var post_money = "";
      if(data1[i].post_money != null && data1[i].post_money != undefined){

          post_money = "(含运费:￥" + data1[i].post_money +")";

      }
      var orderGoodsList = [];
      if(data1[i].orderGoodsList != null && data1[i].orderGoodsList != undefined){
        orderGoodsList = data1[i].orderGoodsList;
      }
      /**
       * 组装html
       *
       * @type {Element}
       */
      var li = document.createElement('div');
      li.className = "list";
      li.setAttribute("data-orderId",zorderinfo_id);
      // 0:待支付
      if(zstate == "0"){
        var order_msg = document.createElement('div');
        order_msg.className = "order-msg";
        order_msg.innerHTML ='<div class="order-num">订单编号：'+zorder_no+'</div>' +
            '<div class="order-type">'+zstateType+'</div>';
        li.appendChild(order_msg);
        for(var j = 0; j < orderGoodsList.length ; j++ ){
          var number = "";
          if(orderGoodsList[j].number != null&& orderGoodsList[j].number != undefined){
            number = orderGoodsList[j].number;
          }
          var goodsName = "";
          if(orderGoodsList[j].goodsName != null&& orderGoodsList[j].goodsName != undefined){
            goodsName = orderGoodsList[j].goodsName;
          }
          var attribute = "";
          if(orderGoodsList[j].attribute != null&& orderGoodsList[j].attribute != undefined){
            attribute = orderGoodsList[j].attribute;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = orderGoodsList[j].image_url;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = imgUrl + orderGoodsList[j].image_url;
          }
          var specification = "";
          if(orderGoodsList[j].specification != null&& orderGoodsList[j].specification != undefined){
            specification = orderGoodsList[j].specification;
          }
          var price = "";
          if(orderGoodsList[j].price != null&& orderGoodsList[j].price != undefined){
            price = "￥" + orderGoodsList[j].price;
          }
          var discount_price = ""
          if(orderGoodsList[j].discount_price != null&& orderGoodsList[j].discount_price != undefined){
            discount_price = "￥" + orderGoodsList[j].discount_price;
          }
          var goods_list = document.createElement("div");
          goods_list.className = "goods-list";
          goods_list.setAttribute("data-type","code01");
          goods_list.setAttribute("data-orderId",zorderinfo_id);
          goods_list.innerHTML ='<div class="left"><img src="'+image_url+'" /></div>'+
              '<div class="center">'+
              '<div class="center-content">'+
              '<div class="goods-desc">'+goodsName+'</div>' +
              '<div class="goods-specification">规格：'+specification+'</div>' +
              '</div>' +
              '</div>' +
              '<div class="right">' +
              '<div class="goods-prise"><span class="z-price">'+price+'</span><span class="s-price">'+ discount_price + '</span></div>' +
              '<div class="goods-num">X'+number+'</div>' +
              '</div>';
          li.appendChild(goods_list);
        }
        var order_all = document.createElement("div");
        order_all.className = "order-all";
        order_all.innerHTML='<div class="goods-all-numm">共' +
            '                            <span>2</span>件商品' +
            '                        </div>' +
            '                        <div class="goods-subtotal">小计：' +
            '                            <span class="red-goods">'+zorder_total_money+'</span><span style="color: #919191;">' + post_money + '</span>' +
            '                        </div>';
        li.appendChild(order_all);
        var handle_way = document.createElement("div");
        handle_way.className = "handle-way";
        handle_way.innerHTML = '<div class="time-over">\n' +
            '<div class="icon"></div>\n' +
            '<span>还有09:23:23订单会自动消失</span>\n' +
            '</div>'+
            '<div class="cancle-order"  data-zorder="'+zorderinfo_id+'">取消订单</div>' +
            '<div class="atOnce-pay">立即付款</div>';
        li.appendChild(handle_way);
        li.setAttribute("data-type","code01");
      }
      // 1:待发货
      if(zstate == "1"){
        var order_msg = document.createElement('div');
        order_msg.className = "order-msg";
        order_msg.innerHTML ='<div class="order-num">订单编号：'+zorder_no+'</div>' +
            '<div class="order-type">'+zstateType+'</div>';
        li.appendChild(order_msg);
        var specificationId ="";
        for(var j = 0; j < orderGoodsList.length ; j++ ){
          var number = "";
          if(orderGoodsList[j].number != null&& orderGoodsList[j].number != undefined){
            number = orderGoodsList[j].number;
          }
          var goodsName = "";
          if(orderGoodsList[j].goodsName != null&& orderGoodsList[j].goodsName != undefined){
            goodsName = orderGoodsList[j].goodsName;
          }
          var attribute = "";
          if(orderGoodsList[j].attribute != null&& orderGoodsList[j].attribute != undefined){
            attribute = orderGoodsList[j].attribute;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = orderGoodsList[j].image_url;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = imgUrl + orderGoodsList[j].image_url;
          }
          var specification = "";
          if(orderGoodsList[j].specification != null&& orderGoodsList[j].specification != undefined){
            specification = orderGoodsList[j].specification;
          }
          var price = "";
          var prices = "";
          if(orderGoodsList[j].price != null&& orderGoodsList[j].price != undefined){
            price = "￥" + orderGoodsList[j].price;
            prices = orderGoodsList[j].price;
          }
          var discount_price = ""
          if(orderGoodsList[j].discount_price != null&& orderGoodsList[j].discount_price != undefined){
            discount_price = "￥" + orderGoodsList[j].discount_price;
          }
          var orderGoodsLists = "";
          if(orderGoodsList[j].orderGoodsId != undefined && orderGoodsList[j].orderGoodsId != null){
            orderGoodsLists =orderGoodsList[j].orderGoodsId;
          }
          if(orderGoodsList[j].specificationId != null&& orderGoodsList[j].specificationId != undefined){
            if(specificationId == ""){
              specificationId = orderGoodsList[j].specificationId;
            }else{
              specificationId = specificationId + "," + orderGoodsList[j].specificationId;
            }
          }
          var goods_list = document.createElement("div");
          goods_list.className = "goods-list";
          goods_list.setAttribute("data-type","code02");
          goods_list.setAttribute("data-orderId",zorderinfo_id);
          goods_list.innerHTML ='<div class="left"><img src="'+image_url+'" /></div>'+
              '<div class="center">'+
              '<div class="center-content">'+
              '<div class="goods-desc">'+goodsName+'</div>' +
              '<div class="goods-specification">规格：'+specification+'</div>' +
              '</div>' +
              '</div>' +
              '<div class="right">' +
              '<div class="goods-prise"><span class="z-price">'+price+'</span><span class="s-price">'+ discount_price + '</span></div>' +
              '<div class="goods-num">X'+number+'</div>' +
              '<div class="refund"><span goods-amount="'+prices+'" good-id="'+orderGoodsLists+'" class="th">退货</span></div>' +
              '</div>';
          li.appendChild(goods_list);
        }
        var order_all = document.createElement("div");
        order_all.className = "order-all";
        order_all.innerHTML='<div class="goods-all-numm">共' +
            '                            <span>2</span>件商品' +
            '                        </div>' +
            '                        <div class="goods-subtotal">小计：' +
            '                            <span class="red-goods">'+zorder_total_money+'</span><span style="color: #919191;">' + post_money + '</span>' +
            '                        </div>';
        li.appendChild(order_all);
        var handle_way = document.createElement("div");
        handle_way.className = "handle-way";
        handle_way.innerHTML = '<div class="remind-store">提醒发货</div>' +
            '<div data-specid="'+specificationId+'" class="add-cart">加入购物车</div>';
        li.appendChild(handle_way);
        li.setAttribute("data-type","code02");
      }
      // 2:已发货
      if(zstate == "2"){
        var order_msg = document.createElement('div');
        order_msg.className = "order-msg";
        order_msg.innerHTML ='<div class="order-num">订单编号：'+zorder_no+'</div>' +
            '<div class="order-type">'+zstateType+'</div>';
        li.appendChild(order_msg);
        var specificationId ="";
        for(var j = 0; j < orderGoodsList.length; j++ ){
          var number = "";
          if(orderGoodsList[j].number != null&& orderGoodsList[j].number != undefined){
            number = orderGoodsList[j].number;
          }
          var goodsName = "";
          if(orderGoodsList[j].goodsName != null&& orderGoodsList[j].goodsName != undefined){
            goodsName = orderGoodsList[j].goodsName;
          }
          var attribute = "";
          if(orderGoodsList[j].attribute != null&& orderGoodsList[j].attribute != undefined){
            attribute = orderGoodsList[j].attribute;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = orderGoodsList[j].image_url;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = imgUrl + orderGoodsList[j].image_url;
          }
          var specification = "";
          if(orderGoodsList[j].specification != null&& orderGoodsList[j].specification != undefined){
            specification = orderGoodsList[j].specification;
          }
          var price = "";
          var prices ="";
          if(orderGoodsList[j].price != null&& orderGoodsList[j].price != undefined){
            price = "￥" + orderGoodsList[j].price;
            prices = orderGoodsList[j].price;
          }
          var discount_price = ""
          if(orderGoodsList[j].discount_price != null&& orderGoodsList[j].discount_price != undefined){
            discount_price = "￥" + orderGoodsList[j].discount_price;
          }
          var goods_list = document.createElement("div");
          var orderGoodsLists = "";
          if(orderGoodsList[j].orderGoodsId != undefined && orderGoodsList[j].orderGoodsId != null){
            orderGoodsLists =orderGoodsList[j].orderGoodsId;
          }
          if(orderGoodsList[j].specificationId != null&& orderGoodsList[j].specificationId != undefined){
            if(specificationId == ""){
              specificationId = orderGoodsList[j].specificationId;
            }else{
              specificationId = specificationId + "," + orderGoodsList[j].specificationId;
            }
          }
          goods_list.className = "goods-list";
          goods_list.setAttribute("data-type","code03");
          goods_list.setAttribute("data-orderId",zorderinfo_id);
          goods_list.innerHTML ='<div class="left"><img src="'+image_url+'" /></div>'+
              '<div class="center">'+
              '<div class="center-content">'+
              '<div class="goods-desc">'+goodsName+'</div>' +
              '<div class="goods-specification">规格：'+specification+'</div>' +
              '</div>' +
              '</div>' +
              '<div class="right">' +
              '<div class="goods-prise"><span class="z-price">'+price+'</span><span class="s-price">'+ discount_price + '</span></div>' +
              '<div class="goods-num">X'+number+'</div>' +
              '<div class="refund"><span goods-amount="'+prices+'" good-id="'+orderGoodsLists+'" class="tk">退款</span></div>' +
              '</div>';
          li.appendChild(goods_list);
        }
        var order_all = document.createElement("div");
        order_all.className = "order-all";
        order_all.innerHTML='<div class="goods-all-numm">共' +
            '                            <span>2</span>件商品' +
            '                        </div>' +
            '                        <div class="goods-subtotal">小计：' +
            '                            <span class="red-goods">'+zorder_total_money+'</span><span style="color: #919191;">' + post_money + '</span>' +
            '                        </div>';
        li.appendChild(order_all);
        var handle_way = document.createElement("div");
        handle_way.className = "handle-way";
        handle_way.innerHTML = '<div class="order-tracting">订单跟踪</div>' +
            '<div data-specid="'+specificationId+'" class="add-cart">加入购物车</div>';
        li.appendChild(handle_way);
        li.setAttribute("data-type","code03");
      }
      //  已收货
      if(zstate == "5"){
        var order_msg = document.createElement('div');
        order_msg.className = "order-msg";
        li.setAttribute("data-type","code04");
        order_msg.innerHTML ='<div class="order-num">订单编号：'+zorder_no+'</div>' +
            '<div class="order-type" style="color: #919191">'+zstateType+'</div>';
        li.appendChild(order_msg);
        var specificationId ="";
        for(var j = 0; j < orderGoodsList.length ; j++ ){
          var number = "";
          if(orderGoodsList[j].number != null&& orderGoodsList[j].number != undefined){
            number = orderGoodsList[j].number;
          }
          var goodsName = "";
          if(orderGoodsList[j].goodsName != null&& orderGoodsList[j].goodsName != undefined){
            goodsName = orderGoodsList[j].goodsName;
          }
          var attribute = "";
          if(orderGoodsList[j].attribute != null&& orderGoodsList[j].attribute != undefined){
            attribute = orderGoodsList[j].attribute;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = orderGoodsList[j].image_url;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = imgUrl + orderGoodsList[j].image_url;
          }
          var specification = "";
          if(orderGoodsList[j].specification != null&& orderGoodsList[j].specification != undefined){
            specification = orderGoodsList[j].specification;
          }
          var price = "";
          var prices = "";
          if(orderGoodsList[j].price != null&& orderGoodsList[j].price != undefined){
            price = "￥" + orderGoodsList[j].price;
            prices = orderGoodsList[j].price;
          }
          var discount_price = ""
          if(orderGoodsList[j].discount_price != null&& orderGoodsList[j].discount_price != undefined){
            discount_price = "￥" + orderGoodsList[j].discount_price;
          }
          var orderGoodsLists = "";
          if(orderGoodsList[j].orderGoodsId != undefined && orderGoodsList[j].orderGoodsId != null){
            orderGoodsLists =orderGoodsList[j].orderGoodsId;
          }
          if(orderGoodsList[j].specificationId != null&& orderGoodsList[j].specificationId != undefined){
            if(specificationId == ""){
              specificationId = orderGoodsList[j].specificationId;
            }else{
              specificationId = specificationId + "," + orderGoodsList[j].specificationId;
            }
          }
          var goods_list = document.createElement("div");
          goods_list.className = "goods-list";
          goods_list.setAttribute("data-type","code04");
          goods_list.setAttribute("data-orderId",zorderinfo_id);
          goods_list.innerHTML ='<div class="left"><img src="'+image_url+'" /></div>'+
              '<div class="center">'+
              '<div class="center-content">'+
              '<div class="goods-desc">'+goodsName+'</div>' +
              '<div class="goods-specification">规格：'+specification+'</div>' +
              '</div>' +
              '</div>' +
              '<div class="right">' +
              '<div class="goods-prise"><span class="z-price">'+price+'</span><span class="s-price">'+ discount_price + '</span></div>' +
              '<div class="goods-num">X'+number+'</div>' +
              '<div class="refund"><span goods-amount="'+prices+'" good-id="'+orderGoodsLists+'" class="tk">退款</span><span goods-amount="'+prices+'" good-id="'+orderGoodsLists+'" class="th">退货</span></div>' +
              '</div>';
          li.appendChild(goods_list);
        }
        var order_all = document.createElement("div");
        order_all.className = "order-all";
        order_all.innerHTML='<div class="goods-all-numm">共' +
            '                            <span>2</span>件商品' +
            '                        </div>' +
            '                        <div class="goods-subtotal">小计：' +
            '                            <span class="red-goods">'+zorder_total_money+'</span><span style="color: #919191;">' + post_money + '</span>' +
            '                        </div>';
        li.appendChild(order_all);
        var handle_way = document.createElement("div");
        handle_way.className = "handle-way";
        handle_way.innerHTML = '<div class="delete-order" data-zorder="'+zorderinfo_id+'">删除订单</div>' +
            '<div data-specid="'+specificationId+'" class="add-cart">加入购物车</div>';
        li.appendChild(handle_way);
        li.setAttribute("data-type","code04");
      }
      // 已取消
      if(zstate == "6"){
        var order_msg = document.createElement('div');
        order_msg.className = "order-msg";
        order_msg.innerHTML ='<div class="order-num">订单编号：'+zorder_no+'</div>' +
            '<div class="order-type" style="color: #FE808C">'+zstateType+'</div>';
        li.appendChild(order_msg);
        var specificationId ="";
        for(var j = 0; j < orderGoodsList.length ; j++ ){
          var number = "";
          if(orderGoodsList[j].number != null&& orderGoodsList[j].number != undefined){
            number = orderGoodsList[j].number;
          }
          var goodsName = "";
          if(orderGoodsList[j].goodsName != null&& orderGoodsList[j].goodsName != undefined){
            goodsName = orderGoodsList[j].goodsName;
          }
          var attribute = "";
          if(orderGoodsList[j].attribute != null&& orderGoodsList[j].attribute != undefined){
            attribute = orderGoodsList[j].attribute;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = orderGoodsList[j].image_url;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = imgUrl + orderGoodsList[j].image_url;
          }
          var specification = "";
          if(orderGoodsList[j].specification != null&& orderGoodsList[j].specification != undefined){
            specification = orderGoodsList[j].specification;
          }
          var price = "";
          if(orderGoodsList[j].price != null&& orderGoodsList[j].price != undefined){
            price = "￥" + orderGoodsList[j].price;
          }
          var discount_price = ""
          if(orderGoodsList[j].discount_price != null&& orderGoodsList[j].discount_price != undefined){
            discount_price = "￥" + orderGoodsList[j].discount_price;
          }
          if(orderGoodsList[j].specificationId != null&& orderGoodsList[j].specificationId != undefined){
            if(specificationId == ""){
              specificationId = orderGoodsList[j].specificationId;
            }else{
              specificationId = specificationId + "," + orderGoodsList[j].specificationId;
            }
          }
          var goods_list = document.createElement("div");
          goods_list.className = "goods-list";
          goods_list.setAttribute("data-orderId",zorderinfo_id);
          goods_list.setAttribute("data-type","code05");
          goods_list.innerHTML ='<div class="left"><img src="'+image_url+'" /></div>'+
              '<div class="center">'+
              '<div class="center-content">'+
              '<div class="goods-desc">'+goodsName+'</div>' +
              '<div class="goods-specification">规格：'+specification+'</div>' +
              '</div>' +
              '</div>' +
              '<div class="right">' +
              '<div class="goods-prise"><span class="z-price">'+price+'</span><span class="s-price">'+ discount_price + '</span></div>' +
              '<div class="goods-num">X'+number+'</div>' +
              '</div>';
          li.appendChild(goods_list);
        }
        var order_all = document.createElement("div");
        order_all.className = "order-all";
        order_all.innerHTML='<div class="goods-all-numm">共' +
            '                            <span>2</span>件商品' +
            '                        </div>' +
            '                        <div class="goods-subtotal">小计：' +
            '                            <span class="red-goods">'+zorder_total_money+'</span><span style="color: #919191;">' + post_money + '</span>' +
            '                        </div>';
        li.appendChild(order_all);
        var handle_way = document.createElement("div");
        handle_way.className = "handle-way";
        handle_way.innerHTML = '<div class="delete-order" data-zorder="'+zorderinfo_id+'">删除订单</div>' +
            '<div class="add-cart"  data-specid="'+specificationId+'">加入购物车</div>';
        li.appendChild(handle_way);
        li.setAttribute("data-type","code05");
      }
      // 售后中
      if(zstate == "7"){
        var order_msg = document.createElement('div');
        order_msg.className = "order-msg";
        order_msg.innerHTML ='<div class="order-num">订单编号：'+zorder_no+'</div>' +
            '<div class="order-type" style="color: #FE808C">'+zstateType+'</div>';
        li.appendChild(order_msg);
        var specificationId ="";
        for(var j = 0; j < orderGoodsList.length ; j++ ){
          if(orderGoodsList.length == 0){
            return
          }
          var number = "";
          if(orderGoodsList[j].number != null&& orderGoodsList[j].number != undefined){
            number = orderGoodsList[j].number;
          }
          var goodsName = "";
          if(orderGoodsList[j].goodsName != null&& orderGoodsList[j].goodsName != undefined){
            goodsName = orderGoodsList[j].goodsName;
          }
          var attribute = "";
          if(orderGoodsList[j].attribute != null&& orderGoodsList[j].attribute != undefined){
            attribute = orderGoodsList[j].attribute;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = orderGoodsList[j].image_url;
          }
          var image_url = "";
          if(orderGoodsList[j].image_url != null&& orderGoodsList[j].image_url != undefined){
            image_url = imgUrl + orderGoodsList[j].image_url;
          }
          var specification = "";
          if(orderGoodsList[j].specification != null&& orderGoodsList[j].specification != undefined){
            specification = orderGoodsList[j].specification;
          }
          var price = "";
          if(orderGoodsList[j].price != null&& orderGoodsList[j].price != undefined){
            price = "￥" + orderGoodsList[j].price;
          }
          // var specificationId = "";
          if(orderGoodsList[j].specificationId != null&& orderGoodsList[j].specificationId != undefined){
            if(specificationId == ""){
              specificationId = orderGoodsList[j].specificationId;
            }else{
              specificationId = specificationId + "," + orderGoodsList[j].specificationId;
            }
          }
          var discount_price = ""
          if(orderGoodsList[j].discount_price != null&& orderGoodsList[j].discount_price != undefined){
            discount_price = "￥" + orderGoodsList[j].discount_price;
          }
          var goods_list = document.createElement("div");
          goods_list.className = "goods-list";
          goods_list.setAttribute("data-type","code06");
          goods_list.setAttribute("data-orderId",zorderinfo_id);
          goods_list.innerHTML ='<div class="left"><img src="'+image_url+'" /></div>'+
              '<div class="center">'+
              '<div class="center-content">'+
              '<div class="goods-desc">'+goodsName+'</div>' +
              '<div class="goods-specification">规格：'+specification+'</div>' +
              '</div>' +
              '</div>' +
              '<div class="right">' +
              '<div class="goods-prise"><span class="z-price">'+price+'</span><span class="s-price">'+ discount_price + '</span></div>' +
              '<div class="goods-num">X'+number+'</div>' +
              '</div>';
          li.appendChild(goods_list);
        }
        var order_all = document.createElement("div");
        order_all.className = "order-all";
        order_all.innerHTML='<div class="goods-all-numm">共' +
            '                            <span>2</span>件商品' +
            '                        </div>' +
            '                        <div class="goods-subtotal">小计：' +
            '                            <span class="red-goods">'+zorder_total_money+'</span><span style="color: #919191;">' + post_money + '</span>' +
            '                        </div>';
        li.appendChild(order_all);
        var handle_way = document.createElement("div");
        handle_way.className = "handle-way";
        handle_way.innerHTML = '<div data-specid="'+specificationId+'" class="add-cart">加入购物车</div>';
        li.appendChild(handle_way);
        li.setAttribute("data-type","code06");
      }
      table.appendChild(li);
    }
  }
  /**
   * 订单跟踪
   */
  $(".order-tracting").click(function (event) {
    event.stopPropagation();
    window.location.href="/usercenter/order/logisticstracking.html";
  });
  /**
   * 提醒发货
   *
   */
  $(".glo").on("click", ".remind-store", function (event) {
    event.stopPropagation();
    mui.alert('提醒发货成功！', '', function() {});
  });
  /**
   *退款
   *
   */
  $(".glo").on("click", ".tk", function (event) {
    var a = $(this)[0].getAttribute("good-id");
    var b = $(this)[0].getAttribute("goods-amount");
    sessionStorage.setItem("ordergoodsid",a);
    sessionStorage.setItem("refund_amount",b);
    sessionStorage.setItem("after_sale_type","1");
    event.stopPropagation();
    window.location.href="/usercenter/order/returnreason.html";
  });
  /**
   * 退货
   *
   */
  $(".glo").on("click", ".th", function (event) {
    var a = $(this)[0].getAttribute("good-id");
    var b = $(this)[0].getAttribute("goods-amount");
    sessionStorage.setItem("ordergoodsid",a);
    sessionStorage.setItem("refund_amount",b);
    sessionStorage.setItem("after_sale_type","2");
    event.stopPropagation();
    window.location.href="/usercenter/order/returnreason.html";
  });
  /**
   * 物流跟踪
   *
   */
  $(".glo").on("click", ".order-tracting", function (event) {
    event.stopPropagation();
    window.location.href="/usercenter/order/logisticstracking.html";
  });
  /**
   * delete-order
   *
   * 删除订单
   *
   */
  $(".glo").on("click", ".delete-order", function (event) {
    event.stopPropagation();
    var zorderinfo_id = $(this)[0].getAttribute("data-zorder");
    var btnArray = ['否', '是'];
    mui.confirm('您要删除订单吗？', '', btnArray, function(e) {
      if (e.index == 1) {
        deleteOrder(zorderinfo_id);
      }
    })
  });
  function deleteOrder(zorderinfo_id) {
    console.log(zorderinfo_id);
    $.ajax({
      type: 'GET',
      url: getUrl + '/wxmall/order/deleteOrder',
      data: {
        "zorderinfo_id": zorderinfo_id
      },
      dataType: 'json',
      timeout: 15000,
      headers: headers("order.deleteOrder"),
      success: function(data){
        if(data.success){
          mui.toast(data.msg);
          next = 0;
          getorderlist(state);
          $("#list").html("");
          $('#spinner').show();
        }else{
          mui.toast(data.msg);
        }
      },
      error: function(xhr, type){
      }
    });
  }
  /**
   * 取消订单
   *
   */
  $(".glo").on("click", ".cancle-order", function (event) {
    event.stopPropagation();
    var zorderinfo_id = $(this)[0].getAttribute("data-zorder");
    var btnArray = ['否', '是'];
    mui.confirm('您想取消订单吗？', '', btnArray, function(e) {
      if (e.index == 1){
        canaleOrder(zorderinfo_id);
      }
    })
  });
  function canaleOrder(zorderinfo_id) {
    console.log(zorderinfo_id);
    $.ajax({
      type: 'GET',
      url: getUrl + '/wxmall/order/cancelOrder',
      data: {
        "zorderinfoId": zorderinfo_id
      },
      dataType: 'json',
      timeout: 15000,
      headers: headers("order.cancelOrder"),
      success: function(data){
        if(data.success){
          mui.toast(data.msg);
          next = 0;
          getorderlist(state);
          $("#list").html("");
          $('#spinner').show();
        }else{
          mui.toast(data.msg);
        }
      },
      error: function(xhr, type){
      }
    });
  }
  /**
   * add-cart
   *
   * 加入购物车
   */
  $(".glo").on("click", ".add-cart", function (event) {
    event.stopPropagation();
    var btnArray = ['否', '是'];
    var specificationId = $(this)[0].getAttribute("data-specid");
    mui.confirm('再次购买商品吗？', '', btnArray, function(e) {
      if (e.index == 1) {
        var data1 = {
          "specificationId":specificationId,
          "num":"1"
        }
        tocart(data1);
      }
    });
  });
  /**
   * 加入购物车
   *
   */
  function tocart(data1) {
    $.ajax({
      type: 'POST',
      url: getUrl + '/wxmall/shopcarts/insert',
      data: data1,
      dataType: 'json',
      timeout: 15000,
      // contentType:'application/json',
      headers: headers("shopcarts.insert"),
      context: $('body'),
      success: function(data){
        tocartbefore(data);
      },
      error: function(xhr, type, data){
        console.log(xhr,type,data);
      }
    });
  }
  function tocartbefore(data) {
    if(data.success){
      $(".model").css("display","none");
      mui.toast("已加入购物车");
    }else {
      $(".model").css("display","none");
      mui.toast(data.msg);
    }
  }
  /**
   * atOnce-pay
   *
   */
  $(".glo").on("click", ".atOnce-pay", function (event) {
    event.stopPropagation();
    var btnArray = ['否', '是'];
    mui.confirm('确定立即购买商品？', '', btnArray, function(e) {
      if (e.index == 1) {
        var data = {
          "totalFee": allprice,
          "outTradeNo":outTradeNo
        };
        topay(data);
      }
    });
  });
  function topay() {
    $.ajax({
      type: 'POST',
      url: getUrl + '/wxmall/pay/prepay',
      data: JSON.stringify(data),
      dataType: 'json',
      timeout: 15000,
      headers: headers("pay.prepay"),
      contentType:'application/json',
      success: function(data){
        if(data.success)
          preinvokes(data.data);
        else
          alert(resp.msg);
      },
      error: function(xhr, type){
        alert(JSON.stringify(xhr));
        alert(JSON.stringify(type));
      }
    });
  }
});